window.onload = function () {
    inituser()
    initchannel()
}

/**
 * 用户展示
 */
function inituser() {
    axios.get("/user/getLoginUser").then(resp =>{
        // console.log(resp.data=="")
        if(resp.data != ""){
            var info = resp.data;
            $('avatar').src = "/img/"+info.imgPath
            $('username').innerHTML ="用户名："+info.userName
            $('email').innerHTML = "用户邮箱："+info.email
        }
        else{
            $('userDiv').innerHTML = "你好，请先<a href='/login.html'>登陆</a>"
        }
        
    })
}
function initchannel() {
    axios.get("/channel/findChannels").then(resp =>{
        var info = resp.data;
        var str ="";
        console.log(info.records)
    for(var i=0;i<info.length;i++){
        str += "<tr><td><a href='/posts.html?id="+info[i].id+"'>"+info[i].name+"</a></td><td>"+info[i].desp+"</td><td>"+info[i].postsNum+"</td></tr>";
    }

    $('channeldata').innerHTML = str;
    })
}
